import { Operation } from './operation'
import { RemoveTextOperation } from './remove_text_operation'
import type Editor from './../editor'
/**
 * 插入数据操作
 */
 export class InsertTextOperation extends Operation{
    private _text : string;//插入数据源
    private _startIndex :number;//数据偏移量
    constructor(text : string , startIndex :number){
        super()
        this._text = text;
        this._startIndex = startIndex
    }
    getText () {
        return this._text
    }
    setText (text: string){
        this._text = text
    }
    apply (editor:Editor): void{
        editor.getTextModel().insert(this._startIndex, this._text)
    }
    reverse():Operation{
        return new RemoveTextOperation(this._text,this._startIndex, this._startIndex + this._text.length)
    }
}
export default InsertTextOperation